package com.rcd2.mapper;

import com.rcd2.pojo.Brand;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * ClassName:BrandMapper
 * Package:com.rcd2.mapper
 * ProjectName:servlet
 * Description:
 *
 * @Date:2022/2/9 15:49
 * @Author:Mrhan
 */
public interface BrandMapper {

    /*查询全部数据*/
    @Select("select * from tb_brand")
    List<Brand> selectAll();

    /*插入数据*/
    @Insert("insert into tb_brand values (null,#{brand_name},#{company_name},#{ordered},#{description},#{status})")
    void add(Brand brand);

    /*批量删除*/
    void deleteByIds(@Param("ids") int[] ids);

    /*分页查询*/
    @Select("select * from tb_brand limit #{begin} , #{size}")
    List<Brand> selectByPage(@Param("begin") int begin, @Param("size") int size);

    /*查询总记录条数*/
    @Select("select count(*) from tb_brand")
    int selectTotalCount();

    /*查询条件+分页查询, 查询数据*/
    List<Brand> selectByPageAndCondition(@Param("begin") int begin, @Param("size") int size, @Param("brand") Brand brand);

    /** 根据条件查询总记录数
     * 只有一个参数Brand对象,这时候:
     * 1,取对象中的brand_name等属性时,可以直接用brand_name
     * 2,不用添加@Param("brand")
     *
     * 如果像上面的selectByPageAndCondition(),有多个参数时,
     * 1,取对象中的brand_name等属性时,要用brand.brand_name
     * 2,必须添加@Param("brand")
     * */
    int selectTotalCountByCondition(Brand brand);

}
